// Created by plusminus on 10:46:37 PM - Feb 26, 2009
package org.anddev.arcc.checkers;

import java.io.File;
import java.io.FilenameFilter;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author Nicolas Gramlich
 */
public class DrawableChecker extends AbstractBaseChecker {
	// ===========================================================
	// Constants
	// ===========================================================
	
	public static final String BASEDIRECTORY = "drawable";

	// ===========================================================
	// Fields
	// ===========================================================

	// ===========================================================
	// Constructors
	// ===========================================================

	public DrawableChecker(final File pProjectResourceDir, final String[] pDrawableDirectories) {
		super(pProjectResourceDir, pDrawableDirectories);
	}

	// ===========================================================
	// Getter & Setter
	// ===========================================================

	// ===========================================================
	// Methods from SuperClass/Interfaces
	// ===========================================================
	
	@Override
	protected String getBaseDirectory() {
		return BASEDIRECTORY;
	}

	@Override
	protected FilenameFilter getFilenameFilter() {
		return new FilenameFilter(){
			@Override
			public boolean accept(File dir, String name) {
				return name.endsWith(".png") 
					|| name.endsWith(".gif") 
					|| name.endsWith(".bmp")
					|| name.endsWith(".jpg")
					|| name.endsWith(".jpeg");
			}
		};
	}
	
	@Override
	protected Map<String, List<String>> checkFile(final String pResourceFolder, final File pFile) {
		if(pFile == null)
			throw new IllegalArgumentException();

		final Map<String, List<String>> out = new HashMap<String, List<String>>();
		
		/* We need to crop the file-ending of the name, as this is also done by appt. */
		final String fileName = pFile.getName();
		final String filenameWithoutEnding = fileName.substring(0, fileName.lastIndexOf("."));
		
		
		final List<String> existing = out.get(filenameWithoutEnding);
		/* If no representations existed before, add a new List. */
		if(existing != null){
			existing.add(pResourceFolder);
		}else{
			final List<String> newList = new ArrayList<String>();
			newList.add(pResourceFolder);
			out.put(filenameWithoutEnding, newList);
		}
		
		return out;
	}

	// ===========================================================
	// Methods
	// ===========================================================

	// ===========================================================
	// Inner and Anonymous Classes
	// ===========================================================
}
